Skip to content

fix(pm-stack): claimant session fetch must prove completeness — escalating limit, fail closed (#4757) - #6756

Merged
dezren39 merged 1 commit into
mainfrom
queue/fallback-4757-session-pagination
Nov 7, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/fallback-4757-session-pagination

Conversation

@developing-today

@developing-today developing-today Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4757.

Problem (triage-confirmed live this shift, Lane W)

GET /api/session truncates at 50 entries by default. poll.py's fetch_sessions() treated that page as the complete list — the claimant's cap accounting and stuck-bound session lookup both ran over a 50-row window. Live numbers at fix time: the server holds 9,601 sessions / 7,583 roots; the truncated page reported ~50 live roots. Any active root outside the newest-50 page was invisible to the cap count (room overstated → launch into a saturated fleet), and a bound session outside the page read as missing ("gone") to stuck-bound classification.

What the live server actually does (probed this shift)

  • No params → exactly 50 rows. ?limit=1000 → 1000 rows (limit honoured).
  • offset is NOT honoured: ?limit=1000&offset=1000 returns the same first 1000 ids as offset 0. (The first implementation paginated with offset behind a non-advancement guard — it correctly failed closed to None on the live server, which is how this was caught. That design is replaced, not shipped.)
  • A ?limit=10000 read returns all 9,601 rows in ~0.9s.

Change

  • poll.py fetch_sessions(): escalating-limit read — limit 1000 → 10000 → 100000; the first read whose count is below its limit is the complete list by construction. A read at its limit every time, or any failed/non-list read, returns None (fail closed → cap_room: null, launch nothing) rather than certifying a possibly-truncated list.
  • claimant.py supervision_step: the same list-verb correction poll.py got in opencode-claimant(poll/claimant): snapshot rewrite dropped poll.py's test-pinned cap API (36/36 tests error) and inverted cap_room — idle reads as saturated, busy launches unbounded #6609 — the deployed repo-queue binary rejects list --worker, so supervision's row fetch silently fetched nothing; it now calls list --queue <q> --status claimed and reads rich rows (progress.session_id) with a flattened-row fallback. (Supervision's session existence check was already per-id GET /api/session/<id> and is unchanged.)
  • Tests: five new fetch-layer tests in test_poll.py stubbing _server_get (short read complete in one call; escalation finds the whole list; count exactly at a limit escalates; failed read fails closed; count at every limit fails closed). The 36 pinned tests are untouched.

Verification

  • Laptop: python3 -m unittest pm-stack/opencode-claimant/test_poll.py — 41/41 OK.
  • Live: fetch_sessions() returns all 9,601 sessions in 0.4s; summarize_cap over the complete list reports 7,583 live roots / 15 active / cap_room 21 (the truncated page had reported ~50 live roots).

Filed and worked in queue fallback mode (queue backend down, code#6619) by Lane W. One heartbeat comment on #4757 was posted via the developing.today GitHub App after the user token hit a secondary rate limit.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…ating limit, fail closed (#4757)

GET /api/session truncates at 50 by default; poll.py treated that page as the whole list, understating live roots ~150x (true count 7,583 vs the 50-row page) and making bound sessions outside the page read as gone. The endpoint honours limit but not offset (an offset page repeats the first page — verified live), so fetch_sessions now reads with an escalating limit (1000, 10000, 100000) and accepts the first read that returns below its limit as complete by construction; a read at its limit every time, or any failed/non-list read, fails closed to None (cap_room null). claimant.py supervision_step gets the same list-verb correction as poll.py in #6609 (the deployed binary rejects list --worker) and reads rich rows (progress.session_id) with a flattened-row fallback. Five fetch-layer tests stub _server_get: short read, escalation, exact-limit escalation, failed read fail-closed, at-every-limit fail-closed. The 36 pinned tests are untouched and pass; live: fetch_sessions returns all 9,601 sessions in 0.4s, summarize_cap reports 7,583 live / 15 active / room 21.
@developing-today
developing-today Bot requested review from a team and dezren39 as code owners November 7, 2026 03:56
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c30b2fd-d747-4044-a6bf-d767766caf4e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@developing-today

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode-claimant: cap and supervision read GET /api/session, which truncates at 50 — active roots undercounted, live bound sessions reported gone

1 participant